//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Input;
using OpenLS.Spreadsheet.UI.Internals;
using OpenLS.Spreadsheet.UI.Internals.Resources;

namespace OpenLS.Spreadsheet.UI
{
    public class WorksheetLayoutCommands
    {
        static public RoutedUICommand FreezeFirstColumn { get { return EnsureCommand(CommandId.FreezeFirstColumn); } }
        static public RoutedUICommand FreezePanes { get { return EnsureCommand(CommandId.FreezePanes); } }
        static public RoutedUICommand UnfreezePanes { get { return EnsureCommand(CommandId.UnfreezePanes, "FreezePanes"); } }
        static public RoutedUICommand FreezeTopRow { get { return EnsureCommand(CommandId.FreezeTopRow); } }
        static public RoutedUICommand ToggleSplitPanes { get { return EnsureCommand(CommandId.ToggleSplitPanes, "WindowSplit"); } }
        static public RoutedUICommand HideWorkbook { get { return EnsureCommand(CommandId.HideWorkbook, "WindowHide"); } }
        static public RoutedUICommand UnhideWorkbook { get { return EnsureCommand(CommandId.UnhideWorkbook, "WindowUnhide"); } }
        #region man
        enum CommandId
        {
            FreezePanes,
            UnfreezePanes,
            FreezeTopRow,
            FreezeFirstColumn,
            ToggleSplitPanes,
            HideWorkbook,
            UnhideWorkbook,
            Last
        }
                static RoutedUICommand EnsureCommand(CommandId idCommand)
        {
            return EnsureCommand(idCommand, idCommand.ToString());
        }
        static RoutedUICommand EnsureCommand(CommandId idCommand, string propertyName)
        {
            lock (_internalCommands.SyncRoot)
            {
                if (_internalCommands[(int)idCommand] == null)
                {
                    var newCommand = new RoutedUICommand(GetUIText(idCommand), propertyName, typeof(SpreadsheetCommands));
                    _internalCommands[(int)idCommand] = newCommand;
                }
            }
            return _internalCommands[(int)idCommand];
        }
        private static readonly RoutedUICommand[] _internalCommands = new RoutedUICommand[(int)CommandId.Last];
        private static string GetUIText(CommandId idCommand)
        {
            switch (idCommand)
            {
                case CommandId.HideWorkbook:
                    return UIStringTable.HideWorkbook;
                case CommandId.UnhideWorkbook:
                    return UIStringTable.UnhideWorkbook;
                case CommandId.FreezePanes:
                    return UIStringTable.FreezePanes;
                case CommandId.UnfreezePanes:
                    return UIStringTable.UnfreezePanes;
                case CommandId.FreezeTopRow:
                    return UIStringTable.FreezeTopRow;
                case CommandId.FreezeFirstColumn:
                    return UIStringTable.FreezeFirstColumn;
                case CommandId.ToggleSplitPanes:
                    return UIStringTable.ToggleSplitPanes;

                default: throw new NotImplementedException();
            }
        }
        #endregion
    }
}
